package com.hskn.hss.module.videoplan.controller;

import com.github.pagehelper.Page;
import com.hskn.hss.core.annotation.SysLog;
import com.hskn.hss.core.controller.BaseController;
import com.hskn.hss.core.enums.BusinessType;
import com.hskn.hss.entity.AjaxResult;
import com.hskn.hss.module.tlequip.mapper.TlEquipMapper;
import com.hskn.hss.module.videoplan.entity.VideoPlan;
import com.hskn.hss.module.videoplan.mapper.VideoPlanMapper;
import com.hskn.hss.module.videoplan.service.IVideoPlanService;
import com.hskn.hss.module.videoplan.to.VideoPlanDeleteTO;
import com.hskn.hss.module.videoplan.to.VideoPlanTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * 录像计划
 *
 * @author lny
 * @date 2021-11-18
 */
@Api(tags = {"-video_plan"}, description = "录像计划")
@RestController
@Slf4j
@RequestMapping("/hss/videoPlan")
public class VideoPlanController extends BaseController {

    @Autowired
    IVideoPlanService videoPlanService;

    /**
     * 查询
     */
    @ApiOperation(value = "录像计划查询", notes = "录像计划查询")
    @ApiResponses({@ApiResponse(code = 200, message = "ok", response = VideoPlan.class)})
    @PostMapping("/list")
    public AjaxResult list(@RequestBody @Validated VideoPlanTO videoPlanTO) {
        try {
            Integer pageSize = videoPlanTO.getSize();
            Integer pageNum = videoPlanTO.getPage();
            Page page = startPage(pageNum, pageSize);
            return AjaxResult.success(getDataTable(videoPlanService.list(videoPlanTO), page.getTotal()));
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return AjaxResult.fail(e.getMessage());
        }
    }

    /**
     * 保存
     */
    @SysLog(businessType = BusinessType.INSERT, tableName = "video_plan", bean = VideoPlan.class, beanMapper = VideoPlanMapper.class,
            names = "equipcode", twoIsId = false, twoTableName = "tl_equip", twoBeanMapper = TlEquipMapper.class, twoNames = "bindobjname")
    @ApiOperation(value = "录像计划保存", notes = "录像计划保存")
    @ApiResponses({@ApiResponse(code = 200, message = "ok")})
    @PostMapping("/save")
    public AjaxResult save(@RequestBody @Validated VideoPlanTO videoPlanTO, HttpServletRequest request) {
        try {
            return videoPlanService.save(videoPlanTO);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return AjaxResult.fail(e.getMessage());
        }
    }

    /**
     * 修改
     */
    @SysLog(businessType = BusinessType.UPDATE, tableName = "video_plan", idKey = "id", bean = VideoPlan.class, beanMapper = VideoPlanMapper.class,
            names = "equipcode", twoIsId = false, twoTableName = "tl_equip", twoBeanMapper = TlEquipMapper.class, twoNames = "bindobjname")
    @ApiOperation(value = "录像计划修改", notes = "录像计划修改")
    @ApiResponses({@ApiResponse(code = 200, message = "ok")})
    @PostMapping("/update")
    public AjaxResult update(@RequestBody @Validated VideoPlanTO videoPlanTO, HttpServletRequest request) {
        try {
            return videoPlanService.update(videoPlanTO);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return AjaxResult.fail(e.getMessage());
        }
    }

    /**
     * 删除
     */
    @SysLog(businessType = BusinessType.DELETE, tableName = "video_plan", idKey = "id", bean = VideoPlan.class, beanMapper = VideoPlanMapper.class,
            names = "equipcode", twoIsId = false, twoTableName = "tl_equip", twoBeanMapper = TlEquipMapper.class, twoNames = "bindobjname")
    @ApiOperation(value = "录像计划删除", notes = "录像计划删除")
    @ApiResponses({@ApiResponse(code = 200, message = "ok")})
    @PostMapping("/delete")
    public AjaxResult delete(@RequestBody @Validated VideoPlanTO videoPlanTO, HttpServletRequest request) {
        try {
            return videoPlanService.delete(videoPlanTO);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return AjaxResult.fail(e.getMessage());
        }
    }

    /**
     * 批量删除
     */
    @SysLog(businessType = BusinessType.DELETE, tableName = "video_plan", idKey = "id", bean = VideoPlan.class, beanMapper = VideoPlanMapper.class,
            names = "equipcode", twoIsId = false, twoTableName = "tl_equip", twoBeanMapper = TlEquipMapper.class, twoNames = "bindobjname")
    @ApiOperation(value = "录像计划批量删除", notes = "录像计划批量删除")
    @ApiResponses({@ApiResponse(code = 200, message = "ok")})
    @PostMapping("/deleteBatch")
    public AjaxResult deleteBatch(@RequestBody @Validated VideoPlanDeleteTO videoPlanDeleteTO, HttpServletRequest request) {
        try {
            return videoPlanService.deleteBatch(videoPlanDeleteTO);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return AjaxResult.fail(e.getMessage());
        }
    }

}
